<script setup lang='ts'>
import { onMounted, ref } from "vue";
import { userLikeData, userCollectData } from "../api/api";
import content from "../components/content.vue";
import { useRoute, useRouter } from "vue-router";
import { page } from "../utils/reload";
const { loading, onRefresh } = page()
const router = useRouter()
const route = useRoute()
const title = ref()
const data = ref([])
onMounted(() => {
    title.value = route.query.title
    if (title.value === '我的喜欢') {
        userLive()
    } else {
        userCollect()
    }
})
//用户喜爱数据
const userLive = async () => {
    const res = await userLikeData({ mail: localStorage.getItem('mail') as string })
    data.value = res.data.data
}
//用户收藏数据
const userCollect = async () => {
    const res = await userCollectData({ mail: localStorage.getItem('mail') as string })
    data.value = res.data.data
}
const onClickLeft = () => history.back();
const toSearch = () => {
    router.push({ name: 'search' })
}
</script>

<template>
    <van-nav-bar fixed placeholder :title left-text="返回" color="black" left-arrow @click-left="onClickLeft">
        <template #right>
            <van-icon name="search" size="24" @click="toSearch" color="black" />
        </template>
    </van-nav-bar>
    <van-pull-refresh v-model="loading" @refresh="onRefresh">
        <div class="conent">
            <content :data></content>
        </div>
    </van-pull-refresh>
</template>

<style scoped>
.conent {
    width: 100%;
    box-sizing: border-box;
    padding: 5px;
    min-height: calc(100vh - 100px);
}
</style>